﻿module Runner {
    export enum equationType {
        addition,
        subtraction,
        multiplication,
        division
    }
    var additionTemplates: string[] =
        [
            '{0} plus {1}',
            'Add {0} to {1}'
        ];
    var subtractionTemplates: string[] =
        [
            '{1} take away {0}',
            '{1} subtract {0}'
        ];

    export function askQuestion(number1: number, number2: number, eqType: equationType, template: number = null) {
        var localTemplate: string;
        var answer;
        switch (eqType) {
            case equationType.addition:
                localTemplate = selectTemplate(additionTemplates, template);
                answer = number1 + number2;
                break;
            case equationType.subtraction:
                localTemplate = selectTemplate(subtractionTemplates, template);
                answer = number2 - number1;
                break;
        }

        var templateString = localTemplate.replace(/\{0\}/, number1.toString());
        templateString = templateString.replace(/\{1\}/, number2.toString());

        return [templateString, answer];
    }

    export function selectTemplate(templates: string[], templateNumber?: number) : string {
        if (templateNumber != null) {
            return templates[templateNumber];
        }

        return templates[Math.floor(Math.random() * templates.length)];
    }
}